/**
 * Created by Administrator on 2017/8/7.
 */
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Moniter {
    public static final String apiurl = "http://localhost/app/coinmonitor/index.php?m=api&a=insert";
    public static  final String bterurl = "https://bter.com/trade/ICO_CNY";
    public static void main(String[] args) {
        new Moniter();
    }
    Moniter() {
        while(true) {
            try {
                Crawl();
                Thread.sleep(15000);
            } catch(Exception e) {}
        }
    }
    private void Crawl() {
        Runnable r = new worker();
        Thread w = null;
        try {
            w = new Thread(r, "");
            w.start();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    private ArrayList getCoins() {
        ArrayList result = new ArrayList();
        Connection conn = null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            String url="jdbc:mysql://127.0.0.1:3306/coinmonitor";
            //yEE4KmwWH8N
            conn = DriverManager.getConnection(url, "root","");
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select coin_id,update_url from cm_coins");
            Integer k = 0;
            while (rs.next()){
                System.out.println();
                result.add(String.valueOf(rs.getInt(1))+","+rs.getString(2));
                k++;
            }
            rs.close();
            stmt.close();
            conn.close();
        }catch(Exception e1){
            e1.printStackTrace();
        }
        return result;
    }
}

class worker implements Runnable {
    public void run() {
        String[] web = Thread.currentThread().getName().split(",");
        String body = WNet.Get(Moniter.bterurl);
        if (body.length()>10) {
            List<NameValuePair> data = new ArrayList<NameValuePair>();
            data.add(new BasicNameValuePair("body", body));
            String r = WNet.Post(Moniter.apiurl, data);
            System.out.println(r);
        }
    }
}